# -*- encoding: utf-8 -*-
"""

PyCharm open函数的详解
2024年10月20日21时13分
by wenyang

"""


def main():
    filepath = "./test.txt"
    # 通过使用open函数来读取文件 通过使用try except finally 来捕获异常
    try:
        file = open(filepath, "r")
        content = file.read()
        print(content)
    except IOError:
        print("文件读写有问题")
    finally:
        if file in locals():
            file.close()
        else:
            print("文件不存在")
    # 使用with open 来进读取文件
    with open(filepath, "r") as f:
        content = f.readlines()
        print(content)



if __name__ == "__main__":
    main()
